package bstsetcode;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/16 9:25
 * 非普通插入排序
 * 而是对于区间的插入排序
 */
public class InsertionSort {
//    [left,right] 注意区间
    public static <E extends Comparable<E>> void sort(E[] arr,int left,int right){

        for (int i = left; i <=right; i++) {
            E t = arr[i];
            int j ;
            for ( j = i; j-1>=left && t.compareTo(arr[j-1]) <0 ; j--) {
                arr[j]=arr[j-1];
            }
            arr[j] = t;
        }
    }

    public static void main(String[] args) {
        Integer[] arr = {1,6,8,3,4,6};
        InsertionSort.sort(arr,0,arr.length-1);
        for(int n : arr){
            System.out.print(n+" ");
        }
    }
}
